
<%@page import="java.util.HashMap"%>
<%@page import="java.io.ByteArrayOutputStream"%>
<%@page import="java.io.ByteArrayInputStream"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.awt.Image"%>
<%@page import="java.awt.Graphics"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.image.BufferedImage"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    /*
   out.clear();
   out = pageContext.pushBody(); 
   
   NWDB.NWDB mydb=new NWDB.NWDB();
   NWDB.IProduct pp=new NWDB.ImplProduct(mydb.getConnection());
   mydb.setIProduct(pp);
   
   
   int pid=Integer.parseInt(request.getParameter("pp"));   
  // int pid=5;
   byte[] bb=mydb.GetProductImageById(pid);
   InputStream buffin = new ByteArrayInputStream(bb);
   BufferedImage ii=ImageIO.read(buffin);
   int x ;
   int y ;
  // Integer.parseInt(request.getParameter("x"))
   //Integer.parseInt(request.getParameter("y"));
   //int x = 300;
   //int y = 300;
   
   
   BufferedImage newii=null;  
   if(request.getParameter("x")!=null)
   {  x=Integer.parseInt(request.getParameter("x"));
        
   
   }
   else
       x = ii.getWidth();
   
   if(request.getParameter("y")!=null)
      y = Integer.parseInt(request.getParameter("y"));
   else
        y=ii.getHeight();
   
    newii=new BufferedImage(x,y,BufferedImage.TYPE_INT_RGB);
  
   if(ii.getHeight()>ii.getWidth())
            newii=new BufferedImage(y,x,BufferedImage.TYPE_INT_RGB);
        else
            newii=new BufferedImage(x,y,BufferedImage.TYPE_INT_RGB);
   
  
   Graphics gg=newii.getGraphics();
   gg.drawImage(ii,0,0,newii.getWidth() , newii.getHeight(), null); 
   ByteArrayOutputStream baos = new ByteArrayOutputStream();    
   ImageIO.write(newii, "jpg", baos);
    bb = baos.toByteArray();    
    response.setContentType("image/jpeg");  
    response.getOutputStream().write(bb,0,bb.length);
    */
    
   out.clear();
   out = pageContext.pushBody(); 
    response.setContentType("image/jpeg");  
   NWDB.NWDB mydb=new NWDB.NWDB();
   NWDB.IProduct pp=new NWDB.ImplProduct(mydb.getConnection());
   mydb.setIProduct(pp);
   //int productId=10;
   int productId=Integer.parseInt(request.getParameter("pid"));   
   int pic=Integer.parseInt(request.getParameter("pp"));   
  HashMap<String, Object> res= mydb.GetProductImageById_4pic(productId);
  byte[] bb =(byte[]) res.get("產品圖片_"+pic);  
  
   InputStream buffin = new ByteArrayInputStream(bb);
   BufferedImage ii=ImageIO.read(buffin);
   int x ;
   int y ;
  
   BufferedImage newii=null;  
   if(request.getParameter("x")!=null)
   {  x=Integer.parseInt(request.getParameter("x"));
        
   
   }
   else
       x = ii.getWidth();
   
   if(request.getParameter("y")!=null)
      y = Integer.parseInt(request.getParameter("y"));
   else
        y=ii.getHeight();
   
    newii=new BufferedImage(x,y,BufferedImage.TYPE_INT_RGB);
  
    Graphics gg=newii.getGraphics();
   gg.drawImage(ii,0,0,newii.getWidth() , newii.getHeight(), null); 
   ByteArrayOutputStream baos = new ByteArrayOutputStream();    
   ImageIO.write(newii, "jpg", baos);
    bb = baos.toByteArray();    
    
    
   mydb.close();
   response.getOutputStream().write(bb);
  
    
    
  
%>
